package com.wgchao.authmanager.application.dispatch;

import com.wgchao.authmanager.application.filter.AuthMethod;
import com.wgchao.authmanager.application.filter.Authentication;
import com.wgchao.authmanager.application.filter.TokenAuthentication;
import com.wgchao.authmanager.application.service.AuthorityService;
import com.wgchao.authmanager.domain.params.LoginInfo;
import com.wgchao.authmanager.infrastructure.resp.BackResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: AuthorityService
 * @author: wgchao
 * @createTime: 2020/5/12 5:17 PM
 * @Description: 身份验证
 */
@RestController
@RequestMapping("/aum/dispatch/authority")
@Api(value = "/aum/dispatch/authority", description = "内部服务调用")
public class AuthorityDispatchService {
    @Autowired
    private AuthorityService authorityService;
    @Autowired
    private TokenAuthentication tokenAuthentication;

    /**
     * 外部申请token
     * @param loginInfo
     * @return
     */
    @PostMapping("/accessToken")
    @ApiOperation(value = "申请token")
    public BackResult<String> accessToken(@RequestBody LoginInfo loginInfo){
        String accessToken = authorityService.accessToken(loginInfo, "external");
        return BackResult.success().setData(accessToken);
    }

    @PostMapping("/accessToken/auth")
    @ApiOperation(value = "检校token有效性")
    public BackResult authentication(@RequestHeader(required = true) String accessToken){
        String uname = authorityService.authenticationToken(accessToken);
        return BackResult.success().setData(uname);
    }


}
